<?php 
@session_start();
if($_SERVER['REQUEST_METHOD'] == 'POST'){
	@header('Expires: ' . gmdate("D, d M Y H:i:s", time()+1000) . ' GMT');
	@header('Cache-Control: public,must-revalidate');
	@header("Pragma: no-cache");
}
///////////////////////////////////////////////////////
function pagenavigator($page, $row_total, $page_size, $pagegroup_size,$class,$url) 
{
	//$andpage=(strrpos ($url,"?")===false)?"?page=":"&page=";
        $andpage = "p";
	$page_total = floor(($row_total-1)/$page_size)+1;
	if(!$page || $page > $page_total || $page < 1)
		$page = 1;
	$group = floor(($page-1)/$pagegroup_size)+1;
	$start_page = (($group-1)*$pagegroup_size)+1;
	$end_page = $start_page+$pagegroup_size-1;
	if ($end_page>$page_total) 
		$end_page = $page_total;
	if ($page_total>1) {
		$str='<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr height=20><td align=center>';
		if ($end_page>$pagegroup_size)
			$start_group = $pagegroup_size;
		else
			$start_group = 0;
		if ($group>1)
			$str.= '<a style="text-decoration: none;" href="'.$url.$andpage.($start_page-$pagegroup_size).'/"><b>[Previous '.$pagegroup_size.' pages]</b></a>';
		for ( $i=$start_page ; $i <= $end_page ;$i++)
		{
			$j=$i+$page_size;
			$begin = ($i-1)*$page_size + 1;
			$end = $begin + $page_size - 1; 
			if ($i == $page)
				$str.= " <b>[$i]</b> ";
			else
				$str.= ' <a style="text-decoration: none;" href="'.$url.$andpage.$i.'/"> <b>'.$i.'</b></a> ';
		}
		if ($page_total-$end_page>$pagegroup_size)
			$end_group = $pagegroup_size;
		else
			$end_group = $page_total-$end_page;
		if ($end_page<$page_total)
			$str.= '<a style="text-decoration: none;" href="'.$url.$andpage.($end_page+1).'/"><b>[Next '.$pagegroup_size.' pages]</b></a>';
		$str.='</td></tr></table>';
		return $str;
	}	
}
function pagenavigator_1($page, $row_total, $page_size, $pagegroup_size,$class,$url) 
{
	$andpage='';//(strrpos ($url,"?")===false)?"?page=":"&page=";
	$page_total = floor(($row_total-1)/$page_size)+1;
	if(!$page || $page > $page_total || $page < 1)
		$page = 1;
	$group = floor(($page-1)/$pagegroup_size)+1;
	$start_page = (($group-1)*$pagegroup_size)+1;
	$end_page = $start_page+$pagegroup_size-1;
	if ($end_page>$page_total) 
		$end_page = $page_total;
	if ($page_total>1) {
		$str='<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr height=20><td align=center>';
		if ($end_page>$pagegroup_size)
			$start_group = $pagegroup_size;
		else
			$start_group = 0;
		if ($group>1)
			$str.= '<a style="text-decoration: none;" href="'.$url.$andpage.($start_page-$pagegroup_size).'.html" class="'.$class.'"><b>[Previous '.$pagegroup_size.' pages]</b></a>';
		for ( $i=$start_page ; $i <= $end_page ;$i++)
		{
			$j=$i+$page_size;
			$begin = ($i-1)*$page_size + 1;
			$end = $begin + $page_size - 1; 
			if ($i == $page)
				$str.= ' <span class="'.$class.'"><b>['.$i.']</b></span> ';
			else
				$str.= ' <a style="text-decoration: none;" href="'.$url.$andpage.$i.'.html" class="'.$class.'"> <b>'.$i.'</b></a> ';
		}
		if ($page_total-$end_page>$pagegroup_size)
			$end_group = $pagegroup_size;
		else
			$end_group = $page_total-$end_page;
		if ($end_page<$page_total)
			$str.= '<a style="text-decoration: none;" href="'.$url.$andpage.($end_page+1).'.html" class="'.$class.'"><b>[Next '.$pagegroup_size.' pages]</b></a>';
		$str.='</td></tr></table>';
		return $str;
	}	
}
//strip all html tag
function strip_html($str){
	return str_replace(">","&gt;",str_replace("<","&lt;",$str));
}
function strip_quote($str){
	return str_replace("'","''",$str);
}
function strip_quotes($str){
	$str = stripslashes($str);
	return str_replace("\"","&quot;",str_replace("'","&#39;",$str));
}
function strip_special($str){
	return eregi_replace("([\./~@?=%&! ]+)","",$str);		
}
function remove_tag($tag,$data){
	while(eregi("<".$tag,$data)){
		$it = stripos($data,"<".$tag);
		$it2 = stripos($data,"</".$tag.">")+strlen($tag)+3;
		$temp = substr($data,0,$it);
		$temp2 = substr($data,$it2,strlen($data));
		$data = $temp.$temp2;
	}
	return $data;
}
function RemoveSign($str)
{
	$coDau=array("à","á","ạ","ả","ã","â","ầ","ấ","ậ","ẩ","ẫ","ă","ằ","ắ"
	,"ặ","ẳ","ẵ","è","é","ẹ","ẻ","ẽ","ê","ề","ế","ệ","ể","ễ","ì","í","ị","ỉ","ĩ",
	"ò","ó","ọ","ỏ","õ","ô","ồ","ố","ộ","ổ","ỗ","ơ"
	,"ờ","ớ","ợ","ở","ỡ",
	"ù","ú","ụ","ủ","ũ","ư","ừ","ứ","ự","ử","ữ",
	"ỳ","ý","ỵ","ỷ","ỹ",
	"đ",
	"À","Á","Ạ","Ả","Ã","Â","Ầ","Ấ","Ậ","Ẩ","Ẫ","Ă"
	,"Ằ","Ắ","Ặ","Ẳ","Ẵ",
	"È","É","Ẹ","Ẻ","Ẽ","Ê","Ề","Ế","Ệ","Ể","Ễ",
	"Ì","Í","Ị","Ỉ","Ĩ",
	"Ò","Ó","Ọ","Ỏ","Õ","Ô","Ồ","Ố","Ộ","Ổ","Ỗ","Ơ"
	,"Ờ","Ớ","Ợ","Ở","Ỡ",
	"Ù","Ú","Ụ","Ủ","Ũ","Ư","Ừ","Ứ","Ự","Ử","Ữ",
	"Ỳ","Ý","Ỵ","Ỷ","Ỹ",
	"Đ","ê","ù","à");
	$khongDau=array("a","a","a","a","a","a","a","a","a","a","a"
	,"a","a","a","a","a","a",
	"e","e","e","e","e","e","e","e","e","e","e",
	"i","i","i","i","i",
	"o","o","o","o","o","o","o","o","o","o","o","o"
	,"o","o","o","o","o",
	"u","u","u","u","u","u","u","u","u","u","u",
	"y","y","y","y","y",
	"d",
	"A","A","A","A","A","A","A","A","A","A","A","A"
	,"A","A","A","A","A",
	"E","E","E","E","E","E","E","E","E","E","E",
	"I","I","I","I","I",
	"O","O","O","O","O","O","O","O","O","O","O","O"
	,"O","O","O","O","O",
	"U","U","U","U","U","U","U","U","U","U","U",
	"Y","Y","Y","Y","Y",
	"D","e","u","a");
	$special_char = array("?","/","\\",":","!","`","_","-",'"',".",",","  ","(",")");
	$empty = array("","","","","","","-","",'',"",""," ","","");
	$url = str_replace($coDau,$khongDau,$str);
	$url = str_replace($special_char,$empty,trim($url));
	return strtolower(str_replace(" ","-",$url));
}
function selfURL() { 
$s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
$protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s; 
$port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]); 
return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI']; } 
function strleft($s1, $s2) { return substr($s1, 0, strpos($s1, $s2)); }
?>
